package com.qf05;

public class Ticket implements Runnable{
    private int ticket=100;

    @Override
    public void run() {
        while (true){
           if (!safe()){
               break;
           }
        }
    }

    public synchronized boolean safe(){
        if (ticket<=0){
            return false;
        }
        System.out.println(Thread.currentThread().getName()+"卖了第"+ticket+"张票");
        ticket--;
        return true;
    }
}
